package com.zc.study.thread.多线程第四章节.thread4_1_2;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Service {
    private Lock lock = new ReentrantLock();
    public void  methodA(){
        lock.lock();
        System.out.println(Thread.currentThread().getName()+" begin");
        System.out.println(Thread.currentThread().getName()+System.currentTimeMillis());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+" end");
        lock.unlock();
    }
    public void methodB(){
        lock.lock();
        System.out.println(Thread.currentThread().getName()+" begin");
        System.out.println(Thread.currentThread().getName()+System.currentTimeMillis());
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(Thread.currentThread().getName()+" end");
        lock.unlock();
    }
}
